<template>
  <div class="bread-nav" :class="{ hidden: title.length === 0 }">
    <div
      v-for="(item, index) in itemsWithAll"
      :key="index"
      class="nav-item"
      :class="{ active: index === activeIndex }"
      @click="setActiveIndex(index)"
    >
      <div>{{ item }}</div>
      <el-divider
        v-if="index !== itemsWithAll.length - 1"
        class="vertical-divider"
      />
    </div>
  </div>
</template>

<script>
// import { VIDEO_TITLES } from '../js/index'
export default {
  name: 'BreadNav',
  data() {
    return {
      // items: this.title,
      // 默认激活第一个导航项
      activeIndex: 0,
    };
  },
  props: {
    cameraAllInfo: {
      type: Array,
      default: () => [],
    },
  },
  computed: {
    itemsWithAll() {
      return ['全部', ...this.title];
    },
    title() {
      return this.cameraAllInfo.map((item) => item.channelName);
    },
  },
  watch: {
    activeIndex: {
      handler(newVal) {
        this.$emit('change-nav', newVal);
      },
      immediate: true,
    },
  },
  methods: {
    setActiveIndex(index) {
      this.activeIndex = index;
    },
  },
};
</script>

<style scoped lang="scss">
.bread-nav {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: flex-start; /* 左对齐 */
  gap: 10px; /* 项之间的间距 */
  padding: 10px;
  background-color: #f5f5f5; /* 背景颜色 */
  box-sizing: border-box;
  &.hidden {
    display: none;
  }
}

.nav-item {
  font-size: 14px;
  color: #333;
  cursor: pointer;
  transition: color 0.3s ease;
  display: flex;
  align-items: center;
  height: 30px;
}

.nav-item:hover {
  color: #007bff; /* 鼠标悬停时的颜色变化 */
}

.nav-item.active {
  color: #007bff; /* 激活时的颜色变化 */
  font-weight: bold; /* 激活时的字体加粗 */
  border-bottom: 2px solid #007bff; /* 激活时的下划线 */
}
.vertical-divider {
  height: 1em;
  width: 1px;
  background-color: #ccc;
  margin-left: 10px;
}
</style>
